package com.szu.smart_illustrator.rest;


import com.szu.smart_illustrator.common.R;
import com.szu.smart_illustrator.dto.param.picture.*;
import com.szu.smart_illustrator.dto.result.picture.GetPictureTypesResultDto;
import com.szu.smart_illustrator.entity.Picture;
import com.szu.smart_illustrator.entity.Type;
import com.szu.smart_illustrator.service.PictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;


/**
 * 图片相关接口
 *
 * @author 冼铧城
 * @date 2023/11/23
 */
@RestController
@RequestMapping("picture")
public class PictureController {

    @Autowired
    PictureService pictureService;

 @GetMapping("complete")
 void complete(String id,String src){
     System.out.println(id);
     System.out.println(src);
     PictureService.cMap.put(Long.valueOf(id),src);
 }


    @PostMapping("searchSharedPicture")
        public R<List<Picture>> searchSharedPicture(@RequestBody SearchSharedPictureParamDto dto){
        return  pictureService.searchSharedPicture(dto);
    }

    @PostMapping("searchUserPicture")
        public R<List<Picture>> searchUserPicture(@RequestBody SearchUserPictureParamDto dto){
        return  pictureService.searchUserPicture(dto);
    }


    /**
     * 取消share
     *
     * @param dto
     * @return {@link R}<{@link String}>
     */
    @PostMapping("cancelShare")
        public R<String> cancelShare(@RequestBody CancelShareParamDto dto){
        return  pictureService.cancelShare(dto);
    }

    /**
     * share图片（图片收藏之后才可以分享）
     *
     * @param dto
     * @return {@link R}<{@link String}>
     */
    @PostMapping("sharePicture")
    public R<String> sharePicture(@RequestBody SharePictureParamDto dto){
     return  pictureService.sharePicture(dto);
}


    /**
     * 取消收藏
     *
     * @param dto
     * @return {@link R}<{@link String}>
     */
    @PostMapping("cancelCollect")
        public R<String> cancelCollect(@RequestBody CancelCollectParamDto dto){
         return  pictureService.cancelCollect(dto);
    }


    /**
     * collect图片
     *
     * @param dto
     * @return {@link R}<{@link String}>
     */
    @PostMapping("CollectPicture")
        public R<String> collectPicture(@RequestBody CollectPictureParamDto dto){
         return  pictureService.collectPicture(dto);
    }


    /**
     * 获取用户图片类型
     * @param dto
     * @return {@link R}<{@link GetPictureTypesResultDto}>
     */
    @PostMapping("GetUserPictureTypes")
        public R<List<Type>> getUserPictureTypes(@RequestBody GetPictureTypesParamDto dto){
         return  pictureService.getUserPictureTypes(dto);
    }

    /**
     * 获取所有图片类型（共享图库需要用到）
     *
     * @return {@link R}<{@link List}<{@link Type}>>
     */
    @PostMapping("GetAllPictureTypes")
    public R<List<String>> getAllPictureTypes(){
        return  pictureService.getAllPictureTypes();
    }


    /**
     * 搜索图片

     * @param dto
     * @return {@link R}<{@link List}<{@link Picture}>>
     */
    @PostMapping("SearchPictures")
       public R<List<Picture>> searchPictures(@RequestBody SearchPicturesParamDto dto){
        return  pictureService.searchPictures(dto);
   }

    /**
     * 文生图片
     *
     * @param dto
     * @return {@link R}<{@link Picture}>
     */
    @PostMapping("GeneratePictureWithText")
       public R<Picture> generatePictureWithText(@RequestBody GeneratePictureWithTextParamDto dto){
        return  pictureService.generatePictureWithText(dto);
   }


    /**
     * 生成图片用图片
     *
     * @param dto
     * @return {@link R}<{@link Picture}>
     */
    @PostMapping("GeneratePictureWithPicture")
       public R<Picture> generatePictureWithPicture(@ModelAttribute GeneratePictureWithPictureParamDto dto) throws IOException, InterruptedException {
        return  pictureService.generatePictureWithPicture(dto);
   }

    /**
     * 上传图片
     * @param dto
     * @return {@link R}<{@link String}>
     * @throws IOException
     */
    @PostMapping("UploadImage")
       public R<String> uploadImage(@ModelAttribute UploadImageParamDto dto) throws IOException {
        return pictureService.uploadImage(dto);
   }


}
